package fun.liuyu2783.dtc.bff.web;

import fun.liuyu2783.dtc.bff.dto.Trade;
import fun.liuyu2783.dtc.bff.feign.MarketFeign;
import fun.liuyu2783.dtc.bff.feign.OrderFeign;
import fun.liuyu2783.dtc.common.Response;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("trade")
public class TradeController {

    @Autowired
    private MarketFeign marketFeign;
    @Autowired
    private OrderFeign orderFeign;

    @RequestMapping("create")
    @GlobalTransactional(rollbackFor = Exception.class)
    public Response<Trade> create(@RequestBody Trade trade){
        log.info("xid={}", RootContext.getXID());
        marketFeign.add(trade.getId());
        orderFeign.add(trade.getId());
        return Response.success();
    }
}
